<?php

namespace App\Model;

use EasySwoole\ORM\AbstractModel;
use EasySwoole\ORM\DbManager;


class User extends AbstractModel
{

    	protected $tableName = 'user';
		protected $autoTimeStamp = true;
	    protected $createTime = 'create_at';
	    protected $updateTime = 'update_at';
	    
	    public function test(){
	    	
			
			// 开启事务
			$strat = DbManager::getInstance()->startTransaction();
			
			// 更新操作

			$res = User::create()->update([
			    'username' => 'new'
			], ['id' => 1]);
			
				
			// $model = User::create([
			//     'username' => 'admin',
			//     'password'  => 123456,
			// ]);
			
			// $res = $model->save();
		
			
			// 不管更新成功还是失败，直接回滚
		//	$rollback = DbManager::getInstance()->rollback();
			
		
			// 返回false 因为连接已经回滚。事务关闭。
			$commit = DbManager::getInstance()->commit();
			
			var_dump($commit);
			
	    }
}